package com.example.confirm1.confing;

import com.rabbitmq.client.ConfirmCallback;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;


/**
 * ClassName:MyConfirmCallBack
 * Package:com.example.confirm1.confing
 * Description:
 *
 * @Author:ZhangXin
 * @Create:2023/8/14-14:47
 * @Version:v1.0
 */
@Component
@Slf4j
public class MyConfirmCallBack implements RabbitTemplate.ConfirmCallback {

    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        log.info("关联id为:{}", correlationData.getId());
        if (ack) {
            log.info("消息正确的到达交换机");
            return;
        }

        //ack 为 false 说明没有到达交换机
        log.error("消息没有到达交换机,原因为:{}", cause);
    }
}
